﻿Imports CalificadorPremiosOscarDAL.pcs.dao

Namespace pcs.dao
    Public Class CeremoniaDAO
        Inherits DAOBase

        Public Function ObtenerCeremonias() As System.Linq.IQueryable(Of Ceremonia)
            Return (From r In Entitie.Ceremonia Order By r.id_ceremonia Ascending Select r)
        End Function

        Public Function ObtenerCeremoniasGridView() As System.Linq.IQueryable(Of Object)
            Return From r In Entitie.Ceremonia Order By r.id_ceremonia Ascending
                   Select New With {
                        .id_ceremonia = r.id_ceremonia,
                        .fecha_inicio_ceremonia = r.fecha_inicio_ceremonia,
                        .fecha_fin_ceremonia = r.fecha_fin_ceremonia,
                        .descripcion_ceremonia = r.descripcion_ceremonia
                       }
        End Function

        Public Function ObtenerCeremonias(ByVal id_ceremonia As String) As System.Linq.IQueryable(Of Ceremonia)
            Return (From r In Entitie.Ceremonia Where r.id_ceremonia.Contains(id_ceremonia) Order By r.id_ceremonia Ascending Select r)
        End Function

        Public Function ObtenerCeremoniasGridView(ByVal id_ceremonia As String) As System.Linq.IQueryable(Of Object)
            Return From r In Entitie.Ceremonia Where r.id_ceremonia.Contains(id_ceremonia) Order By r.id_ceremonia Ascending
                   Select New With {
                        .id_ceremonia = r.id_ceremonia,
                        .fecha_inicio_ceremonia = r.fecha_inicio_ceremonia,
                        .fecha_fin_ceremonia = r.fecha_fin_ceremonia,
                        .descripcion_ceremonia = r.descripcion_ceremonia
                       }
        End Function


        Public Function ObtenerCeremonia(ByVal id_ceremonia As String) As Ceremonia
                Return (From r In Entitie.Ceremonia Where r.id_ceremonia = id_ceremonia Select r).FirstOrDefault()
        End Function

        Public Sub AgregarCeremonia(ByVal ceremonia As Ceremonia)
            Entitie.Ceremonia.AddObject(ceremonia)
            Try
                Entitie.SaveChanges()
            Catch ex As Exception
                Throw ex
            End Try
        End Sub

        Public Sub ModificarCeremonia(ByVal ceremonia As Ceremonia)
            Try
                    Dim cer As Ceremonia = (From r In Entitie.Ceremonia Where r.id_ceremonia = ceremonia.id_ceremonia Select r).FirstOrDefault()
                    cer.fecha_fin_ceremonia = ceremonia.fecha_fin_ceremonia
                    cer.fecha_inicio_ceremonia = ceremonia.fecha_inicio_ceremonia
                    cer.descripcion_ceremonia = ceremonia.descripcion_ceremonia
                    Entitie.SaveChanges()
            Catch ex As Exception
                Throw ex
            End Try
        End Sub

        Public Sub EliminarCeremonia(ByVal ceremonia As Ceremonia)
            Dim temp As Ceremonia = (From r In Entitie.Ceremonia Where r.id_ceremonia = ceremonia.id_ceremonia Select r).FirstOrDefault()
            Entitie.Ceremonia.DeleteObject(temp)
            Try
                Entitie.SaveChanges()
            Catch ex As Exception
                Throw ex
            End Try
        End Sub

    End Class
End Namespace

